package com.xxcxcxcx.xc_crop.common.blocks.crops.minecraft.TreeSaplingBlock;

import com.mojang.logging.LogUtils;
import com.xxcxcxcx.xc_crop.common.Configuration;
import com.xxcxcxcx.xc_crop.common.ReadConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.world.level.block.grower.AbstractTreeGrower;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import org.slf4j.Logger;

import java.util.ArrayList;

public class OakSaplingBlock extends SaplingBlock implements ReadConfig {
    public static String ConfigKey = "oak-sapling";
    public OakSaplingBlock(AbstractTreeGrower p_55978_, Properties p_55979_) {
        super(p_55978_, p_55979_);
    }
    private static final Logger LOGGER = LogUtils.getLogger();
    protected static ArrayList<String> biomeWhiteList = new ArrayList<>();
    protected static boolean whitelistRead = false;//保证config只读一次
    public boolean canBiome(BlockPos pos,LevelReader levelReader){
        Biome.BiomeCategory currentBiome = Biome.getBiomeCategory(levelReader.getBiome(pos));
        if(!whitelistRead)ReadConfigMessage();
        return biomeWhiteList.isEmpty()||biomeWhiteList.contains(currentBiome.getName());
    }
    public void ReadConfigMessage(){
        biomeWhiteList = Configuration.whitelistStrtoArraylist(Configuration.Config.get(ConfigKey));
        whitelistRead = true;
    }
    public boolean canSurvive(BlockState p_52282_, LevelReader p_52283_, BlockPos p_52284_) {
        return canBiome(p_52284_,p_52283_) && p_52283_.canSeeSky(p_52284_) && super.canSurvive(p_52282_, p_52283_, p_52284_);
    }
}
